package com.hyz.service.permission.impl;

import client.AssetClient;
import com.hyz.model.dto.ApprovalResultRequest;
import com.hyz.model.vo.AssetSecondmentResponse;
import com.hyz.service.permission.FinancialService;
import com.hyz.util.AssetSecondmentUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.ResponseResult;
import pojo.asset.assetSecondment.AssetSecondment;
import pojo.asset.assetSecondment.AssetSecondmentResult;

import java.util.List;

/**
 * @author HGD
 * @date 2022/10/10 0:03
 */
@Service
public class FinancialServiceImpl implements FinancialService {
    @Autowired
    private AssetClient assetClient;
    @Autowired
    private AssetSecondmentUtils asUtils;

    @Override
    public ResponseResult<List<AssetSecondmentResponse>> flGetAssetSecondments() {
        ResponseResult<List<AssetSecondment>> result = assetClient.flGetAssetSecondments();
        return asUtils.getAssetSecondmentResponse(result);
    }

    @Override
    public ResponseResult<List<AssetSecondmentResponse>> flUpdateAssetSecondment(ApprovalResultRequest request) {
        int code = 200;
        ResponseResult<String> result = assetClient.flUpdateAssetSecondment(request.getApprovalId()
                , request.getResult() ? AssetSecondmentResult.FINANCIAL_AGREE : AssetSecondmentResult.FAILED);
        if (result.getStatus() != code) {
            return new ResponseResult<>(result.getStatus(), result.getMsg());
        }
        return flGetAssetSecondments();
    }

}
